package vn.gq.tym.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

public class DialogHelper {
	
	public static AlertDialog showExitDialog(Context context, String message, final IDialogHelper listener) {
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setMessage(message);
		builder.setCancelable(true)
		.setIcon(android.R.drawable.btn_star_big_on)
		.setTitle("ỨNG DỤNG VIỆT")
		.setPositiveButton("Đánh giá", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				if (listener != null) {
					listener.onOk();
				}
			}
		})
		.setNegativeButton("Thoát", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				if (listener != null) {
					listener.onCancel();
				}
			}
		});
		AlertDialog dialog = builder.create();
		dialog.show();
		return dialog;
	}
	
	public static void showConfirm(Context context, String message, final IDialogHelper listener, boolean cancelable) {
		showConfirm(context, message, "Có", "Không", listener, cancelable);
	}
	
	public static void showConfirm(Context context, String message, String btn1Label, String btn2Label, final IDialogHelper listener, boolean cancelable) {
		try {
			AlertDialog.Builder builder = new AlertDialog.Builder(context);
			builder.setMessage(String.valueOf(message))
			.setCancelable(cancelable)
			.setPositiveButton(btn1Label, new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					if (listener != null) listener.onOk();
				}
			})
			.setNegativeButton(btn2Label, new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					if (listener != null) listener.onCancel();
				}
			})
			.create()
			.show();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void showMessage(Context context, String msg, boolean cancelable) {
		try {
			AlertDialog.Builder builder = new AlertDialog.Builder(context);
			builder.setMessage(String.valueOf(msg))
			.setCancelable(cancelable)
			.setPositiveButton("OK", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			})
			.create()
			.show();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
}
